<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>热力图</title>
    <style type="text/css">
        html{height:100%}
        body{height:100%;margin:0px;padding:0px}
        #container{height:100%}
    </style>
    <script type="text/javascript" src="js/apiv2.0.min.js"></script>
    <script type="text/javascript" src="js/Heatmap_min.js"></script>
</head>

<body>
<!-- 1XjLLEhZhQNUzd93EjU5nOGQ -->
<div id="container"></div>
<script type="text/javascript">

    var outputPath = 'tiles/';    //地图瓦片所在的文件夹
    var fromat = ".png";    //格式

    var tileLayer = new BMap.TileLayer();
    tileLayer.getTilesUrl = function (tileCoord, zoom) {
        var x = tileCoord.x;
        var y = tileCoord.y;
        var url = outputPath + zoom + '/' + x + '/' + y + fromat;
        return url;
    }
    var tileMapType = new BMap.MapType('tileMapType', tileLayer);

    var map = new BMap.Map("container", { mapType: tileMapType ,minZoom:7,maxZoom:15});

    //var map = new BMap.Map("container");          // 创建地图实例
    var point = new BMap.Point(108.94646555063274, 34.34726881662395);  // 创建点坐标
    map.centerAndZoom(point, 11);                 // 初始化地图，设置中心点坐标和地图级别
    map.enableScrollWheelZoom(true); // 允许缩放
    var bottom_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT});// 左上角，添加比例尺
    var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //右上角，仅包含平移和缩放按钮
    map.addControl(bottom_left_control);
    map.addControl(top_right_navigation);

    var points =[
        {"lng":108.944858,"lat":34.319623,"count":20},
        {"lng":108.937224,"lat":34.226012,"count":41},
        {"lng":108.943715,"lat":34.217608,"count":15},
        {"lng":108.935813,"lat":34.364656,"count":40},
        {"lng":108.896603,"lat":34.236591,"count":100},
        {"lng":108.826443,"lat":34.297737,"count":26},
        {"lng":109.012571,"lat":34.281299,"count":15},
        {"lng":109.056578,"lat":34.310259,"count":31},
        {"lng":108.959148,"lat":34.245152,"count":35},
        {"lng":108.895708,"lat":34.200924,"count":25},
        {"lng":108.63307,"lat":34.113521,"count":40},
        {"lng":108.94708,"lat":34.162661,"count":39},
        {"lng":108.954868,"lat":34.305604,"count":18},
        {"lng":108.944784,"lat":34.25305,"count":39},
        {"lng":109.074599,"lat":34.376364,"count":11},
        {"lng":109.324681,"lat":34.161603,"count":39},
        {"lng":108.94275,"lat":34.236618,"count":111}];

    if(!isSupportCanvas()){
        alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~')
    }
    //详细的参数,可以查看heatmap.js的文档 https://github.com/pa7/heatmap.js/blob/master/README.md
    //参数说明如下:
    /* visible 热力图是否显示,默认为true
     * opacity 热力的透明度,1-100
     * radius 势力图的每个点的半径大小
     * gradient  {JSON} 热力图的渐变区间 . gradient如下所示
     *	{
            .2:'rgb(0, 255, 255)',
            .5:'rgb(0, 110, 255)',
            .8:'rgb(100, 0, 255)'
        }
        其中 key 表示插值的位置, 0~1.
            value 为颜色值.
     */
    heatmapOverlay = new BMapLib.HeatmapOverlay({"radius":20});
    map.addOverlay(heatmapOverlay);
    heatmapOverlay.setDataSet({data:points,max:100});

    //判断浏览区是否支持canvas
    function isSupportCanvas(){
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }
</script>
</body>
</html>
